import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/pages/lf_forget_password/lf_forget_password_logic.dart';
import 'package:largefriends/pages/lf_login/lf_login_logic.dart';
import 'package:largefriends/res/lf_color.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_fonts.dart';
import 'package:largefriends/res/lf_text_style.dart';
import 'package:largefriends/res/lf_widget_ext.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/widgets/lf_app_bar.dart';
import 'package:largefriends/widgets/lf_button.dart';

import '../../config/lf_config.dart';
import '../../widgets/lf_auto_complete.dart';
import '../../widgets/lf_text_label_filed.dart';

class LfLoginPage extends StatefulWidget {
  const LfLoginPage({super.key});

  @override
  State<LfLoginPage> createState() => _LfLoginPageState();
}

class _LfLoginPageState extends State<LfLoginPage> {
  final LfLoginLogic logic = Get.put(LfLoginLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: lfAppBar(leadingCallback: () {
        Get.back();
      }),
      body: SingleChildScrollView(
        child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
          30.h.sbh,
          Text(
            appName,
            style: lfTextStyle(sp: 40.sp, fontFamily: fontYoungSerif),
          ).shadeMask,
          60.0.sbh,
          Padding(
              padding: EdgeInsets.symmetric(horizontal: 20.w),
              child: autoCompleteWidget(
                  onSelected: (String value) {
                    logic.email.value = value;
                  },
                  hintText: strYourEmail.tr,
                  focusNode: logic.emailFocusNode,
                  onChanged: (String value) {
                    logic.email.value = value;
                  },
                  controller: logic.emailController)),
          20.0.sbh,
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 20.w),
            child: LfTextLabelFiled(
              textEditingController: logic.passwordController,
              isPassword: true,
              hintText: strPassword.tr,
              prefixIcon: Icon(
                Icons.lock,
                color: colorFF007F,
                size: 20.w,
              ),
              inputFormatters: [
                LengthLimitingTextInputFormatter(16),
                FilteringTextInputFormatter.deny(RegExp('[ ]'))
              ],
              hintStyle: lfTextStyle(
                  sp: 14.sp,
                  fontFamily: fontRegular,
                  color: color210215.withAlpha(128)),
              inputStyle: lfTextStyle(sp: 14.sp, fontFamily: fontMedium),
              onChanged: (value) {
                logic.password.value = value;
              },
            ),
          ),
          5.0.sbh,
          Opacity(
            opacity: 0,
            child: Text(
              strPasswordNotRight.tr,
              style: lfTextStyle(
                sp: 12.sp,
                fontFamily: fontBold,
                color: Colors.red,
              ),
              textAlign: TextAlign.left,
            ),
          ),
          20.0.sbh,
          10.0.sbh,
          Obx(() => LfButton(
                enabled: logic.buttonEnable,
                text: strLogIn.tr,
                onPress: () {
                  logic.login();
                },
              )),
          30.0.sbh,
          InkWell(
            child: Text(strForgotPassword.tr,
                style: lfTextStyle(
                  sp: 15.sp,
                  fontFamily: fontBold,
                  color: color514F62,
                  decoration: TextDecoration.underline,
                )),
            onTap: () {
              toForgetPassword(email: logic.email.value);
            },
          )
        ]),
      ),
    );
  }
}
